package prticemap;

import java.util.HashMap;

public class Map01 {
    public static void main(String[] args) {
        //hasmap中添加使用put
        //如果添加的键值不存在，会把键值元素添加到集合中
        //添加的键值存在，会覆盖原先的值，把原先的值当做返回值进行返回
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("0001", "haha");
        hashMap.put("0002", "weiha");
        hashMap.put("0003", "ma");
        hashMap.put("0004", "da");
        System.out.println(hashMap);
        String put = hashMap.put("0001", "333");
        System.out.println(put);
        System.out.println(hashMap);
//移除元素
        String weiha = hashMap.remove("0001");
        System.out.println(weiha);
        System.out.println(hashMap);
        //清空
//        hashMap.clear();
//        System.out.println(hashMap);
        //判断是否包含指定的键
        boolean b = hashMap.containsKey("0004");
        System.out.println(b);
        //判断是否包含指定的值
        boolean f = hashMap.containsValue("0004");
        System.out.println(f);
        //集合是否为空
        boolean empty = hashMap.isEmpty();
        System.out.println(empty);
        //长度
        int size = hashMap.size();
        System.out.println(size);


    }
}
